package org.zlb.algorithm.aop;

import org.zlb.algorithm.sort.AbstractSort;
import org.zlb.algorithm.sort.Sortable;

import java.lang.reflect.Proxy;

/**
 * TODO
 *
 * @author zhoulingbo
 * @date 2021/7/8 12:50
 */
public class AopFactory {

    public static Sortable getSort(Class<? extends AbstractSort> clazz) {
        AbstractSort sort;
        try {
            sort = clazz.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
            return null;
        }
        AopSortHandler handler = new AopSortHandler(sort);
        return (Sortable) Proxy.newProxyInstance(clazz.getClassLoader(), AbstractSort.class.getInterfaces(), handler);
    }
}
